import api from "../../../common/api.js";
var datas = {};
Page({

  /**
   * 页面的初始数据
   */
  data: {
    showDialog: false,
    typesIndex: -1,
    timerIndex: -1,
    stayIndex: -1,
    typesPreIndex: -1,
    timerPreIndex: -1,
    stayPreIndex: -1,
    detail: '', //详情
    types: [{
      title: '房源详情',
      types: "detail"
    }, {
      title: '打call活动页',
      types: "call1"
    }, {
      title: ' 打call助力页',
      types: "call2"
    }],
    timer: [{
      title: '今天',
      types: 0
    }, {
      title: '昨日',
      types: 1
    }, {
      title: '最近7天',
      types: 2
    }, {
      title: '7天之前',
      types: 3
    }],
    stay: [{
      title: '1秒以下',
      types: {
        min: '',
        max: 1000
      }
    }, {
      title: '1-5秒',
      types: {
        min: 1000,
        max: 5000
      }
    }, {
      title: '5-10秒',
      types: {
        min: 5000,
        max: 10000
      }
    }, {
      title: '10-20秒',
      types: {
        min: 10000,
        max: 20000
      }
    }, {
      title: '20秒以上',
      types: {
        min: 20000,
        max: ''
      }
    }],
  },
  //拨打电话
  callPhone(e) {
    var num = e.currentTarget.dataset.phonenum;
    wx.makePhoneCall({
      phoneNumber: num,
    })
  },
  //下拉框
  toggleDialog(e) {
    this.setData({
      showDialog: !this.data.showDialog
    });
    if (!this.data.showDialog) {
      var typesIndex = this.data.typesPreIndex,
        timerIndex = this.data.timerPreIndex,
        stayIndex = this.data.stayPreIndex;
      this.setData({
        typesPreIndex: -1,
        timerPreIndex: -1,
        stayPreIndex: -1,
        typesIndex: typesIndex,
        timerIndex: timerIndex,
        stayIndex: stayIndex,
      })
    }
  },
  //重置
  moreReset() {
    var typesIndex = this.data.typesPreIndex,
      timerIndex = this.data.timerPreIndex,
      stayIndex = this.data.stayPreIndex;
    datas = {
      page: 1, //当前页面
      rows: 20, //页面长度
      custId: this.data.custId, //房源详情
      pageType: '', //details call1 call2
      timeMax: '', //停留时间 
      timeMin: '', //停留时间 
      dateEq: '', //0今天 1昨天
      dateMax: '', //浏览时间  7天以内:7
      dateMin: '', //浏览时间  7天以前：7
    }
    this.setData({
      typesPreIndex: -1,
      timerPreIndex: -1,
      stayPreIndex: -1,
      typesIndex: -1,
      timerIndex: -1,
      stayIndex: -1,
    })
  },
  //确定 
  enter() {
    datas.page = 1;
    this.setData({
      showDialog: false,
      custFilter: []
    });
    this.custVp()
  },
  typesChange: function(e) {
    var index = e.currentTarget.dataset.index,
      typesIndex = this.data.typesIndex;
    if (index == typesIndex) {
      datas.pageType = '';
      this.setData({
        typesIndex: -1
      })
    } else {
      datas.pageType = this.data.types[index].types;
      this.setData({
        typesIndex: index
      })
    }
    this.setData({
      typesPreIndex: typesIndex,
    })
  },
  timerChange: function(e) {
    var index = e.currentTarget.dataset.index,
      timerIndex = this.data.timerIndex;

    if (index == timerIndex) {
      datas.pageType = '';
      this.setData({
        timerIndex: -1
      })
      datas.dateEq = '';
      datas.dateMax = '';
      datas.dateMin = '';
    } else {
      switch (this.data.timer[index].types) {
        case 0:
          datas.dateEq = 0;
          datas.dateMax = '';
          datas.dateMin = '';
          break;
        case 1:
          datas.dateEq = 1;
          datas.dateMax = '';
          datas.dateMin = '';
          break;
        case 2:
          datas.dateEq = '';
          datas.dateMax = 7;
          break;
        case 3:
          datas.dateEq = '';
          datas.dateMin = 7;
          break;
      }
      this.setData({
        timerIndex: index
      })
    }
    this.setData({
      timerPreIndex: timerIndex,
    })
  },
  stayChange: function(e) {
    var index = e.currentTarget.dataset.index,
      stayIndex = this.data.stayIndex;
    if (index == stayIndex) {
      datas.timeMin ='';
      datas.timeMax = '';
      this.setData({
        stayIndex: -1
      })
    } else {
      datas.timeMin = this.data.stay[index].types.min;
      datas.timeMax = this.data.stay[index].types.max;
      this.setData({
        stayIndex: index
      })
    }
    this.setData({
      stayPreIndex: stayIndex,
    })
  },
  //跳房源详情
  goSalesDetail(e) {
    var delId = e.currentTarget.dataset.delid;
    wx.navigateTo({
      url: '/pages/house/RentalHouseDetail/RentalHouseDetail?from=1&houdelid=' + delId,
    })
  },
  //获取详情
  getCustDetails() {
    var that = this;
    api.getCustDetails({
      custId: that.data.custId,
    }, (res) => {
      that.setData({
        detail: res.data.content
      })
    })
  },
  //粉丝浏览记录筛选
  custVp() {
    var that = this;
    var custFilter = that.data.custFilter ? that.data.custFilter : [];
    api.custVp(datas, (res) => {
      var newcustFilter = custFilter.concat(res.data.content.rows);
      that.setData({
        custFilter: newcustFilter,
        total: res.data.content.total
      })
    })
  },
  //粉丝浏览记录筛选 加载更多
  listLoadMore(e) {
    const that = this;
    datas.page++;
    if (datas.page > that.data.total) {
      return;
    } else {
      that.custVp();
    }
  },
  /**
   * 生命周期函数--监听页面加载
   */
  onLoad: function(options) {
    var that = this;
    datas = {
      page: 1, //当前页面
      rows: 20, //页面长度
      custId: '', //房源详情
      pageType: '', //details call1 call2
      timeMax: '', //停留时间 
      timeMin: '', //停留时间 
      dateEq: '', //0今天 1昨天
      dateMax: '', //浏览时间  7天以内:7
      dateMin: '', //浏览时间  7天以前：7
    }
    datas.custId = options.custId;
    that.setData({
      custId: options.custId
    })
    that.getCustDetails();
    that.custVp();
  },

  /**
   * 生命周期函数--监听页面初次渲染完成
   */
  onReady: function() {

  },

  /**
   * 生命周期函数--监听页面显示
   */
  onShow: function() {

  },

  /**
   * 生命周期函数--监听页面隐藏
   */
  onHide: function() {

  },

  /**
   * 生命周期函数--监听页面卸载
   */
  onUnload: function() {

  },

  /**
   * 页面相关事件处理函数--监听用户下拉动作
   */
  onPullDownRefresh: function() {

  },

  /**
   * 页面上拉触底事件的处理函数
   */
  onReachBottom: function() {


  }
})